{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "###### Clone the following repository before proceeding ######\n",
    "#### https://github.com/tensorflow/models/tree/master/research/audioset/vggish ########"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('./audioset/vggish/')\n",
    "from vggish_input import wavfile_to_examples\n",
    "import os\n",
    "import numpy as np\n",
    "import subprocess"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "names = {'1': 'CC1', '2': 'HO1', '3': 'CC2', '4': 'HO2'}\n",
    "for movie_idx in ['1', '2', '3', '4']:\n",
    "    command = \"ffmpeg -i Post_20140821_version/7T_MOVIE\" + movie_idx + \"_\" + names[movie_idx] + \"_v2.mp4 -ab 160k -ac 2 -ar 44100 -vn audio_files/audio\" + movie_idx + \".wav\"\n",
    "    subprocess.call(command, shell=True)\n",
    "    data = wavfile_to_examples('./audio_files/audio' + movie_idx + '.wav')\n",
    "    np.save('./audio_feats/audio' + movie_idx + '_audioset.npy', data[:,4:,:])  ## crop to 960ms to match VGGish model input"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
